package 代理设计模式.动态代理;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class CarInvocationHandler implements InvocationHandler {
    private Object target;

    public CarInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //拿到代理对象的属性
        Field name = target.getClass().getDeclaredField("name");
        name.setAccessible(true);
        System.out.println(name.get(target)+"正在被购买");
        //调用这个mthod方法
        method.invoke(target);
        return  null;
    }
}
